/**
 * Created by erfli on 10/15/16.
 */
import {put, take, call, fork} from 'redux-saga/effects';
import * as ActionType from "../Constant/ActionType"
import * as ZhihuAction from "../Actions/zhihu";
import {request} from "../Utils/RequestUtil";
import moment from 'moment'
 const start = function* startRefreshZhihu() {
    try {
        yield put(ZhihuAction.fetchZhihu());
        let b = moment();
        let url = "http://news.at.zhihu.com/api/4/news/before/" + b.format("YYYYMMDD");
        const stories = yield call(request, url);
        yield put(ZhihuAction.refreshZhihuDone(stories));
    } catch (error) {
    }
}

 const Root =  function* watchRefreshZhihu() {
    while (true) {
        yield take(ActionType.Start_Refresh_Zhihu);
        yield fork(start);
    }
}

export default Root;

